package com.ycy.dubbo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DiscoveryController {

  /**
   * 获取 注册中心 元数据
   */
  @Autowired
  private DiscoveryClient discoveryClient;

  @GetMapping("/getp")
  //必须使用 ResponseBody
  @ResponseBody
  public List<ServiceInstance> showProviderInfo() {
    List<ServiceInstance> instances = this.discoveryClient.getInstances("YCY-PROVIDER");
    return instances;
  }

  @GetMapping("/gets")
  //必须使用 ResponseBody
  @ResponseBody
  public List<String> showProviderNames() {
    List<String> services = this.discoveryClient.getServices();
    return services;
  }

}
